<?php

namespace app\common\model;

use app\common\controller\Helper;
use think\Model;

class TieBaComment extends Model
{
    use Helper;

    protected $table = 'tie_ba_comment';

    const READ = 1;
    const READ_NO = 0;
    const REPLY = 1; // 回复
    const REPLY_NO = 0; // 评论

    public static function attributes($attribute, $key = null)
    {
        $list = [
            'is_read' => [
                self::READ_NO => '未读',
                self::READ => '已读',
            ],
            'is_reply' => [
                self::REPLY_NO => '评论',
                self::REPLY => '回复',
            ]
        ];
        return self::attributeReturn($list, $attribute, $key);
    }

    /**
     * 统计帖子下面的评论数
     * @param $tieIds
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getCount($tieIds)
    {
        return static::field('tie_id, count(id) AS count')
            ->where('tie_id', 'in', $tieIds)
            ->group('tie_id')
            ->select()
            ->column('count', 'tie_id');
    }
}